package com.credithc.eagleeye.api.web;
import com.credithc.eagleeye.api.service.SettingService;
import com.credithc.eagleeye.api.service.StatService;
import com.credithc.eagleeye.api.vo.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
/**
 * 描 述: <br/>
 * 作 者: zhangjin<br/>
 * 创 建：2018年02月07日<br/>
 * 版 本：v1.0.0<br>
 * <p>
 * 历 史: (版本) 作者 时间 注释 <br/>
 */
@SuppressWarnings("Duplicates")
@Slf4j
@Controller
public class StatApiCtrl extends BaseApiCtrl {
    @Autowired
    private SettingService settingService;

    @Autowired
    private StatService statService;

    @RequestMapping(value = "/stat/statError", method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ResultVo<List<StatVo>> statError(@RequestBody StatConditionVo statConditionVo) {
        ResultVo<List<StatVo>> resultVo=new ResultVo();
        try {
            List<StatVo> resultList = this.statService.statError(statConditionVo);
            resultVo.setCode("0000");
            resultVo.setData(resultList);
            resultVo.setMsg("处理成功！");
        } catch (Exception e) {
            e.printStackTrace();
            resultVo.setCode("0");
            resultVo.setMsg(e.getMessage());
        }

        return resultVo;
    }

    @RequestMapping(value = "/stat/statPercent", method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ResultVo<List<StatVo>> statPercent(@RequestBody StatConditionVo statConditionVo) {
        ResultVo<List<StatVo>> resultVo=new ResultVo();
        try {
            List<StatVo> resultList = this.statService.statPercent(statConditionVo);
            resultVo.setCode("0000");
            resultVo.setData(resultList);
            resultVo.setMsg("处理成功！");
        } catch (Exception e) {
            e.printStackTrace();
            resultVo.setCode("0");
            resultVo.setMsg(e.getMessage());
        }

        return resultVo;
    }

    @RequestMapping(value = "/stat/statDependency", method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ResultVo<List<StatVo>> statDependency(@RequestBody StatConditionVo statConditionVo) {
        ResultVo<List<StatVo>> resultVo=new ResultVo();
        try {
            List<StatVo> resultList = this.statService.statDependency(statConditionVo);
            resultVo.setCode("0000");
            resultVo.setData(resultList);
            resultVo.setMsg("获取依赖服务成功！");
        } catch (Exception e) {
            e.printStackTrace();
            resultVo.setCode("0");
            resultVo.setMsg(e.getMessage());
        }

        return resultVo;
    }
    @RequestMapping(value = "/stat/statSunburst", method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ResultVo<List<StatSunburstVo>> statSunburst(@RequestBody StatConditionVo statConditionVo) {
        ResultVo<List<StatSunburstVo>> resultVo=new ResultVo();
        try {
            List<StatSunburstVo> resultList = this.statService.statSunburst(statConditionVo);
            resultVo.setCode("0000");
            resultVo.setData(resultList);
            resultVo.setMsg("获取旭日图成功！");
        } catch (Exception e) {
            e.printStackTrace();
            resultVo.setCode("0");
            resultVo.setMsg(e.getMessage());
        }

        return resultVo;
    }

    @RequestMapping(value = "/stat/statUnion", method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public ResultVo<List<StatUnionVo>> statUnion(@RequestBody StatConditionVo statConditionVo) {
        ResultVo<List<StatUnionVo>> resultVo=new ResultVo();
        try {
            List<StatUnionVo> resultList = this.statService.statUnion(statConditionVo);
            resultVo.setCode("0000");
            resultVo.setData(resultList);
            resultVo.setMsg("获取综合分析成功！");
        } catch (Exception e) {
            e.printStackTrace();
            resultVo.setCode("0");
            resultVo.setMsg(e.getMessage());
        }

        return resultVo;
    }
}
